package model;

import helperclasses.DbUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

public class CheckLogin {

	public CheckLogin() {
	}

	private Connection getConnection() throws SQLException {

		DataSource ds = DbUtil.getInstance().getDataSource();
		Connection conn = ds.getConnection();
		return conn;
	}

	public boolean CheckUserAndPassword(String userName, String password)
			throws SQLException {
		String sql;
		Connection conn = getConnection();
		Statement st = conn.createStatement();
		try {
			sql = "SELECT * FROM users" + " WHERE userName =\"" + userName
					+ "\"" + " AND password =\"" + password + "\"";

			ResultSet result = st.executeQuery(sql);
			if (result.next() == false) {
				return false;
			}

		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		} finally {
			st.close();
			conn.close();

		}
		return true;
	}
}
